package io.qifan.desktop.client;

import io.qifan.desktop.client.registry.ViewRegistry;
import io.qifan.desktop.client.views.index.IndexController;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;

@Slf4j
public class ClientApplication extends Application {
    private static Scene scene;

    private static SpringApplication springApplication;

    private static String[] runArgs;

    @Override
    public void start(Stage stage) throws Exception {
        springApplication.run(runArgs);
        scene = new Scene((Parent) ViewRegistry.get(IndexController.class), 640, 480);
        stage.setScene(scene);
        stage.show();
    }

    static void setRoot(Parent parent) throws IOException {
        scene.setRoot(parent);
    }


    public static void launch(String[] args, Class<? extends Application> application, SpringApplication springApplication) {
        runArgs = args;
        ClientApplication.springApplication = springApplication;
        launch(application);
        log.info("应用启动成功");
    }

}
